package xyz.yq56.easytool.utils.collection;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yi qiang
 * @date 2021/10/2 22:21
 */
public class MapUtil {

    private MapUtil(){}

    public static MapBuilder builder() {
        return MapBuilder.newHashMap();
    }


    public static class MapBuilder {
        Map<String, Object> map;

        public MapBuilder(Map<String, Object> map) {
            this.map = map;
        }

        public static MapBuilder newHashMap() {
            return new MapBuilder(new HashMap<>(8));
        }

        public MapBuilder put(String k, Object v) {
            this.map.put(k, v);
            return this;
        }

        public MapBuilder putIfValueNotNull(String key, Object value) {
            if (value != null) {
                return put(key, value);
            }
            return this;
        }

        public Map<String, Object> maps() {
            return this.map;
        }

    }
}
